package com.single;
//单例模式  饿汉式
public class Hungry {
    //在类内部实例化一个实例
    private static Hungry instance = new Hungry();
    //私有的构造函数,外部无法访问
    private Hungry() {
        System.out.println("123");
    }
    //对外提供获取实例的静态方法
    public static Hungry getInstance() {
        return instance;
    }
    public static void main(String[] args) {
        //同一个对象
        Hungry instance = Hungry.getInstance();
        Hungry instance2 = Hungry.getInstance();
        System.out.println(instance);
        System.out.println(instance2);

    }
}

